package com.ticorp.salmofood.log4j;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.PropertyConfigurator;

public class Log4jInit extends HttpServlet {

    private static final long serialVersionUID = 2660625253067659581L;
    private static final String WINDOWS = "Windows";

    public void init() throws ServletException {

	super.init();
	String prefix = null;
	String osname = null;

	try {
	    osname = System.getProperty("os.name");
	} catch (Exception e) {
	    osname = null;
	}

	prefix = getServletContext().getRealPath("/");

	if (osname != null && osname.startsWith(WINDOWS)) {
	    PropertyConfigurator.configure(prefix + "WEB-INF/log4j-windows.properties");
	} else {
	    PropertyConfigurator.configure(prefix + "WEB-INF/log4j-unix.properties");
	}
    }

}
